package com.waimai1.waimai.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.Data;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

@Data
public class PartnerPayConfig {
    private final static String  partnerMerchantId="1618615755";
    private final static String  partnerMerchantSerialNumber="7EBC27EFD27F5A10AD4D588ACD3DC3CE8F244AB9";
    private final static String  partnerApiV3key="IOxbNqaOWnBc0skl17151Xy89mIdYU4k";
//    private final static String  partnerAppid="wx4fe2775ae7278ade";
    public  static Config partnerConfig;

    static {
        try {
            partnerConfig = new RSAAutoCertificateConfig.Builder()
                    .merchantId(partnerMerchantId)
                    .privateKeyFromPath(getPath())
                    .merchantSerialNumber(partnerMerchantSerialNumber)
                    .apiV3Key(partnerApiV3key)
                    .build();
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }
    public static String getPath() throws IOException {
        File filepath = new File("partnercert");
        Path parentPath = Paths.get(filepath.getCanonicalPath());
        // 文件保存路径
        return parentPath.resolve("apiclient_key.pem").toString();
    }
}
